home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Sun Solutions 1997 April to September
/
Sun Solutions CD - APR '97 - SEP '97 (704-3778-12 Rev. H)(Sun Microsystems, Inc.)(1997).iso
/
products
/
bin
/
gui
/
win32
/
src
/
cpp.cpp
next >
Wrap
C/C++ Source or Header
|
1997-02-26
|
11KB
|
386 lines
/***************************************************************************
*
* Filename: Doperl.cpp
*
* Main routine to execute perl scripts using registry information.
*
* Date : 11/20/1995
* Changed By Marc Sacoolas
****************************************************************************/
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <process.h>
#include <errno.h>
#include <string.h>
void ErrorLog(int errno)
{
switch (errno)
{
case 1:
printf("change directory failed \n");
break;
default:
printf("Content-type: text/html\n\n");
printf("<p><p><p><h2>The search portion of this software is not properly installed. Please re-install the software.</h2>\n");
// printf("ErrorCode: %d\n", errno);
break;
}
}
void main(int argc, char **argv)
{
char *getQuery(char *s);
/* open appropriate registry keys */
//#if 0
HKEY softKey,archKey, discKey,volKey;
LONG errVal;
/* open software hive using LOCAL_MACHINE */
if ((errVal=RegOpenKeyEx(HKEY_LOCAL_MACHINE,(LPCTSTR)"Software",0,KEY_ALL_ACCESS,
&softKey)) != ERROR_SUCCESS) {
ErrorLog(2);
printf("Unable to open the hive HKEY_CURRENT_USER\\Software\n");
printf("ErrorCode: %d\n", errVal);
}
/* SunSoft Dir */
if ((errVal=RegOpenKeyEx(softKey,(LPCTSTR)"SunSoft",0,KEY_ALL_ACCESS,
&archKey)) != ERROR_SUCCESS) {
ErrorLog(3);
printf("Unable to open the hive SunSoft");
printf("ErrorCode: %d\n", errVal);
}
/* discKey Dir */
if ((errVal=RegOpenKeyEx(archKey,(LPCTSTR)"Sun Solutions CD",0,KEY_ALL_ACCESS,
&discKey)) != ERROR_SUCCESS) {
ErrorLog(3);
printf("Unable to open the hive discKey");
printf("ErrorCode: %d\n", errVal);
}
/* get specific volume of CD */
if ((errVal=RegOpenKeyEx(discKey,(LPCTSTR)"April 1997",0,KEY_ALL_ACCESS,
&volKey)) != ERROR_SUCCESS) {
ErrorLog(3);
printf("Unable to open the hive April 1997\n");
printf("ErrorCode: %d\n", errVal);
}
/* get values from hive.
* get the PATH */
char PATH[_MAX_PATH], CLASSPATH[_MAX_PATH],JAVA_EXE[_MAX_PATH],JAVAHOME[_MAX_PATH],PRODDIR[_MAX_PATH],NETSCAPEHOME[_MAX_PATH];
DWORD dwLen = _MAX_PATH;
if ((errVal=RegQueryValueEx(volKey,(LPTSTR)"PATH",0,NULL,
(unsigned char *)PATH,&dwLen)) != ERROR_SUCCESS) {
ErrorLog(6);
printf("Unable to open PATH\n");
printf("ErrorCode: %d\n", errVal);
}
/* get the CLASSPATH */
dwLen = _MAX_PATH;
if ((errVal=RegQueryValueEx(volKey,(LPTSTR)"CLASSPATH",0,NULL,
(unsigned char *)CLASSPATH,&dwLen)) != ERROR_SUCCESS) {
ErrorLog(7);
printf("Unable to open CLASSPATH\n");
printf("ErrorCode: %d\n", errVal);
}
/* get the JAVA_EXE */
dwLen = _MAX_PATH;
if ((errVal=RegQueryValueEx(volKey,(LPTSTR)"JAVA_EXE",0,NULL,
(unsigned char *)JAVA_EXE,&dwLen)) != ERROR_SUCCESS) {
ErrorLog(7);
printf("Unable to open JAVA_EXE\n");
printf("ErrorCode: %d\n", errVal);
}
/* get the JAVAHOME*/
dwLen = _MAX_PATH;
if ((errVal=RegQueryValueEx(volKey,(LPTSTR)"JAVAHOME",0,NULL,
(unsigned char *)JAVAHOME,&dwLen)) != ERROR_SUCCESS) {
ErrorLog(7);
printf("Unable to open JAVAHOME\n");
printf("ErrorCode: %d\n", errVal);
}
/* get the PRODDIR */
dwLen = _MAX_PATH;
if ((errVal=RegQueryValueEx(volKey,(LPTSTR)"PRODDIR",0,NULL,
(unsigned char *)PRODDIR,&dwLen)) != ERROR_SUCCESS) {
ErrorLog(7);
printf("Unable to open PRODDIR\n");
printf("ErrorCode: %d\n", errVal);
}
/* get the NETSCAPEHOME */
dwLen = _MAX_PATH;
if ((errVal=RegQueryValueEx(volKey,(LPTSTR)"NETSCAPEHOME",0,NULL,
(unsigned char *)NETSCAPEHOME,&dwLen)) != ERROR_SUCCESS) {
ErrorLog(7);
printf("Unable to open PRODDIR\n");
printf("ErrorCode: %d\n", errVal);
}
//#endif
// execute httpd -- jeeves
//char *Query = convertQuery(getenv("QUERY_STRING"));
SetEnvironmentVariable((LPCTSTR)"PATH",(LPCTSTR)PATH);
SetEnvironmentVariable((LPCTSTR)"CLASSPATH",(LPCTSTR)CLASSPATH);
SetEnvironmentVariable((LPCTSTR)"JAVA_EXE",(LPCTSTR)JAVA_EXE);
SetEnvironmentVariable((LPCTSTR)"JAVAHOME",(LPCTSTR)JAVAHOME);
#if 0
/*printf ("%s\n%s\n%s\n%s\n%s\n%s\n",PATH,CLASSPATH,JAVA_EXE,JAVAHOME,PRODDIR,NETSCAPEHOME);*/
char *Cmd = new char[strlen(JAVA_EXE)+strlen(" -Dserver.root=")+strlen(PRODDIR)+strlen("\\.bin\\httpd\\win32\\jeeves -noasyncgc sun.server.http.HttpServer")+5];
//char *Cmd = new char[strlen(PRODDIR)+strlen("\\.bin\\httpd\\win32\\jeeves\\bin\\httpd.exe")+5];
sprintf(Cmd,"%s -Dserver.root=%s\\.bin\\httpd\\win32\\jeeves -noasyncgc sun.server.ServerProcess",JAVA_EXE,PRODDIR);
//sprintf(Cmd,"%s -Dserver.root=%s\\.bin\\httpd\\win32\\jeeves -noasyncgc sun.server.http.HttpServer",JAVA_EXE,PRODDIR);
//sprintf(Cmd,"%s\\.bin\\httpd\\win32\\jeeves\\bin\\httpd.exe",PRODDIR);
printf("\n\nStarting HTTP Java Server ...\n\n");
#else
char *Cmd = new char [strlen(PRODDIR) + 100];
sprintf(Cmd, "%s\\.bin\\httpd\\win32\\fnord\\fnord.exe", PRODDIR);
printf("\n\nStarting HTTP server ...\n\n");
#endif // FNORD !!
STARTUPINFO StartInfo;
PROCESS_INFORMATION ProcessInfo;
ZeroMemory((void *)&StartInfo, sizeof(STARTUPINFO));
ZeroMemory((void *)&ProcessInfo, sizeof(PROCESS_INFORMATION));
StartInfo.cb = sizeof(STARTUPINFO);
StartInfo.lpDesktop = "";
StartInfo.hStdInput = GetStdHandle(STD_INPUT_HANDLE);
//StartInfo.hStdOutput = (HANDLE CreateFile();
StartInfo.hStdOutput = GetStdHandle(STD_OUTPUT_HANDLE);
StartInfo.hStdError = GetStdHandle(STD_ERROR_HANDLE);
StartInfo.dwFlags = STARTF_USESTDHANDLES;
if (!CreateProcess(NULL,(LPTSTR)Cmd,NULL,NULL,TRUE,
NULL,NULL,NULL,
&StartInfo,&ProcessInfo)) {
printf("create process failed: %d \n", GetLastError());
// delete[] Cmd;
}
char *end_proc = (char *) malloc(5);
char *end_thrd = (char *) malloc(5);
WaitForSingleObject(ProcessInfo.hProcess,1500);
delete[] Cmd;
//GetExitCodeProcess(ProcessInfo.hProcess,(LPDWORD)end_proc);
//GetExitCodeThread(ProcessInfo.hThread,(LPDWORD)end_thrd);
//printf("Exit code proc = %s, thread = %s.\n", end_proc, end_thrd);
#if 0
//system(cmdLine);
FILE *Pfile;
char ErrFile[_MAX_PATH];
sprintf (ErrFile,"%s\\doperl.log",scriptDir);
Pfile = fopen(ErrFile,"w");
int RetVal;
if ((RetVal= system(CmdLine)) != 0) {
switch (errno) {
case E2BIG:
fprintf(Pfile, "doperl failure: Argument list is too big\n");
break;
case ENOENT:
fprintf(Pfile, "doperl failure: Command interpreter cannot be found\n");
break;
case ENOEXEC:
fprintf(Pfile, "doperl failure: Command interpreter file has invalid format and cannot be executed\n");
break;
case ENOMEM:
fprintf(Pfile, "doperl failure: Insufficient memory to run the command\n");
break;
default:
if (errno == -1)
fprintf(Pfile, "doperl failure: Unknown error\n");
else if (errno == 0)
fprintf(Pfile, "doperl failure: perl returned %d\n", retVal);
else if (errno != 0)
fprintf(Pfile, "perl error: %d\n", errno);
else
fprintf(Pfile, "doperl succeeded\n");
break;
}
}
else
fprintf(Pfile, "doperl succeeded\n");
fclose(Pfile);
#endif
char *cmdLine = new char[strlen(NETSCAPEHOME) + 15];
sprintf(cmdLine,"%s",NETSCAPEHOME);
printf ("\n\nStarting Netscape ...\n\n%s",cmdLine);
STARTUPINFO startInfo;
PROCESS_INFORMATION processInfo;
ZeroMemory((void *)&startInfo, sizeof(STARTUPINFO));
ZeroMemory((void *)&processInfo, sizeof(PROCESS_INFORMATION));
startInfo.cb = sizeof(STARTUPINFO);
startInfo.lpDesktop = "";
startInfo.hStdInput = GetStdHandle(STD_INPUT_HANDLE);
startInfo.hStdOutput = GetStdHandle(STD_OUTPUT_HANDLE);
startInfo.hStdError = GetStdHandle(STD_ERROR_HANDLE);
startInfo.dwFlags = STARTF_USESTDHANDLES;
if (!CreateProcess(NULL,(LPTSTR)cmdLine,NULL,NULL,TRUE,
0,NULL,NULL,
&startInfo,&processInfo)) {
printf("create process failed: %d %s \n", GetLastError(), _strerror("error string"));
// delete[] cmdLine;
}
WaitForSingleObject(processInfo.hProcess,INFINITE);
printf("\n before pulse \n");
PulseEvent(ProcessInfo.hProcess);
printf("\n after pulse \n");
CloseHandle(processInfo.hProcess);
CloseHandle(processInfo.hThread);
delete[] cmdLine;
Sleep (10 * 1000);
/* Shut down the httpd server */
//LPDWORD = debug;
LPDWORD *debug = (LPDWORD *) malloc(5);
GetExitCodeProcess (ProcessInfo.hProcess, (LPDWORD)&debug);
printf("\nerror code=%p\n",&debug);
printf("\nTerminate process\n");
TerminateProcess (ProcessInfo.hProcess,0);
TerminateThread (ProcessInfo.hThread,0);
printf("Close handles");
CloseHandle(ProcessInfo.hProcess);
CloseHandle(ProcessInfo.hThread);
GenerateConsoleCtrlEvent(CTRL_C_EVENT,ProcessInfo.dwProcessId);
printf("send ctrl c");
GenerateConsoleCtrlEvent(CTRL_C_EVENT,ProcessInfo.dwProcessId);
printf("send ctrl c");
GenerateConsoleCtrlEvent(CTRL_C_EVENT,ProcessInfo.dwProcessId);
printf("send ctrl c");
//GenerateConsoleCtrlEvent(CTRL_BREAK_EVENT,ProcessInfo.dwProcessId);
//added
//ExitProcess(0);
printf("\nexiting");
#if 0
//system(cmdLine);
FILE *pfile;
char errFile[_MAX_PATH];
sprintf (errFile,"%s\\excite.log",cgiDir);
pfile = fopen(errFile,"w");
int retVal;
if ((retVal= system(cmdLine)) != 0) {
switch (errno) {
case E2BIG:
fprintf(pfile, "doperl failure: Argument list is too big\n");
break;
case ENOENT:
fprintf(pfile, "doperl failure: Command interpreter cannot be found\n");
break;
case ENOEXEC:
fprintf(pfile, "doperl failure: Command interpreter file has invalid format and cannot be executed\n");
break;
case ENOMEM:
fprintf(pfile, "doperl failure: Insufficient memory to run the command\n");
break;
default:
if (errno == -1)
fprintf(pfile, "doperl failure: Unknown error\n");
else if (errno == 0)
fprintf(pfile, "doperl failure: perl returned %d\n", retVal);
else if (errno != 0)
fprintf(pfile, "perl error: %d\n", errno);
else
fprintf(pfile, "doperl succeeded\n");
break;
}
}
else
fprintf(pfile, "doperl succeeded\n");
fclose(pfile);
#endif
printf("at the end");
}